//第一步引入数据
//此文件用来处理请求数据
//引入读取文件fs模块
const fs = require("fs")
//引入处理路径模块path
const path = require("path")
//使用path模块来处理
const filePath = path.join(__dirname, "./data.json");
console.log(filePath);
var all = fs.readFileSync(filePath, "utf-8")


//获取全部数据
const getUserlist = () => {
    try {
        all = all.toString()
        return JSON.parse(all)
    } catch (e) {
        if (e.errno === -4058) {
            fs.writeFileSync(filePath, "{}")
            return {}
        }
    }
}
//获取用户列表
const getUserdatalist = () => {
    let all_data = getUserlist()
    if (!all_data.Userlist) {
        return []
    }
    return all_data.Userlist
}
//添加
const postUserlist = () => {
    let all_data = getUserlist()
    return all_data
}
//导出
module.exports = {
    getUserdatalist,
    postUserlist,
}